package org.example.service.impl;

import org.example.mapper.ArtifactMapper;
import org.example.mapper.ExhibitionMapper;
import org.example.ourEnum.ExhibitionStatus;
import org.example.pojo.domain.Artifact;
import org.example.pojo.domain.Exhibition;
import org.example.pojo.vo.ExhibitionToManyArtifactVo;
import org.example.service.ExhibitionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ExhibitionServiceImpl implements ExhibitionService {
    @Autowired
    private ExhibitionMapper exhibitionMapper;

    @Autowired
    private ArtifactMapper artifactMapper;

    @Override
    public int getEventCount() {
        return exhibitionMapper.countEventsToday(new Date());
    }

    @Override
    public Exhibition getExhibitionById(Integer id) {
        return exhibitionMapper.selectById(id);
    }

    @Override
    public List<Exhibition> getAllExhibitions() {
        return exhibitionMapper.selectAll();
    }

    public List<Exhibition> getPublishedExhibitions(){
        return exhibitionMapper.selectPublished();
    }

    @Override
    public Integer createExhibition(Exhibition exhibition) {
        return exhibitionMapper.insert(exhibition);
    }

    @Override
    public Integer updateExhibition(Exhibition exhibition) {
        return exhibitionMapper.update(exhibition);
    }

    @Override
    public Integer deleteExhibition(Integer id) {
        return exhibitionMapper.deleteById(id);
    }

    @Override
    public List<Exhibition> searchExhibitionsByTitle(String title) {
        return exhibitionMapper.searchByName(title);
    }

    public ExhibitionToManyArtifactVo searchDetailById(Integer id){
        Exhibition exhibition = exhibitionMapper.selectById(id);
        List<Artifact> artifacts = artifactMapper.listShowArtifactByExhibitionId(exhibition.getExhibitionId());
        ExhibitionToManyArtifactVo exhibitionToManyArtifactVo = new ExhibitionToManyArtifactVo();
        exhibitionToManyArtifactVo.setExhibition(exhibition);
        exhibitionToManyArtifactVo.setArtifacts(artifacts);
        return exhibitionToManyArtifactVo;
    }

    public void changeStatus(Integer exhibitionId, ExhibitionStatus published){
        exhibitionMapper.changeStatus(exhibitionId,published);
        return;
    }
}
